package com.ato.mybatis.exception;

import com.ato.mybatis.enums.RestStatusEnum;
import com.ato.mybatis.response.R;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;



/**
 * @author wangjing
 * @create 2021--09--27--下午 2:21
 * 此注解参数：value=com.xxx  要指定哪个包就填什么，默认是全局
 */
@Slf4j
@RestControllerAdvice
public class GlobalException implements ErrorController {
    private static final Logger logger = LoggerFactory.getLogger(GlobalException.class);


    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public R exceptionHandler(Exception e) {
        logger.error("控制台：" + e.getMessage());
        return R.fail(RestStatusEnum.INTERNAL_SERVER_ERROR.getCode(), e.getMessage());
    }
}